package org.edu.modules.classChoise.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.common.system.vo.LoginUser;
import org.edu.modules.classChoise.entity.VeJwSxjx;
import org.edu.modules.classChoise.entity.VeJwSxjxsec;
import org.edu.modules.classChoise.entity.VeJwSxjxstu;
import org.edu.modules.classChoise.entity.VeJwXkdj;
import org.edu.modules.classChoise.service.IVeJwSxjxService;
import org.edu.modules.classChoise.service.IVeJwSxjxstuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 选修教学
 * @Author:
 * @Date: 2021-05-14
 * @Version: V1.0
 */
@Api(tags = "选修教学")
@RestController
@RequestMapping("/classChoise/veJwSxjxstu")
@Slf4j
public class VeJwSxjxstuController extends BaseController<VeJwSxjx, IVeJwSxjxService> {
    @Autowired
    private IVeJwSxjxstuService veJwSxjxstuService;


    /**
     * 已分班的选课学生信息
     *
     * @param sxjxid
     * @return
     */
    @AutoLog(value = "已分班的选课学生信息")
    @ApiOperation(value = "已分班的选课学生信息查询", notes = "已分班的选课学生信息-分页查询")
    @PostMapping(value = "/yfbStuList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sxjxid", value = "选修教课", required = false),
    })
    public Result<?> yfbStuList(@ApiIgnore VeJwSxjxstu veJwSxjxstu,
                                String sxjxid      //选修教课id
            ,
                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                HttpServletRequest req
    ) {

        QueryWrapper<VeJwSxjxstu> queryWrapper = QueryGenerator.initQueryWrapper(veJwSxjxstu, req.getParameterMap());

        //   Integer sxjxid= veJwSxjxstu.getSxjxid();//班级id
        if (sxjxid != null && !sxjxid.equals("")) {
            queryWrapper.eq("b.sxjxid", sxjxid);
        }
        Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo, pageSize);
        IPage<Map<String, Object>> pageList = veJwSxjxstuService.pageMaps(page, queryWrapper);
        return Result.OK(pageList);

    }

    /**
     * 选修教学设置学生
     *
     * @param stuids
     * @param sxjxId
     * @return
     */
    @AutoLog(value = "选修教学设置学生")
    @ApiOperation(value = "选修教学设置学生", notes = "选修教学设置学生")
    @PostMapping(value = "/setScheduleForStu")
    public Result<?> setScheduleForStu(@RequestParam(name = "stuids", required = true) String stuids,
                                       @RequestParam(name = "xkdjids", required = true) String xkdjids,
                                       @RequestParam(name = "sxjxId", required = true) String sxjxId) {//
        if (veJwSxjxstuService.setSxjxForStu(xkdjids.split(","), stuids.split(","), sxjxId)) {
            return Result.OK("设置成功!");
        }
        return Result.error("设置失败!");
    }


    /**
     * 修改信息
     *
     * @param stuids
     * @param sxjxId
     * @return
     */
    @AutoLog(value = "选修教学设置学生退班")
    @ApiOperation(value = "选修教学设置学生退班", notes = "选修教学设置学生退班")
    @PostMapping(value = "/setNoScheduleForStu")
    public Result<?> setNoScheduleForStu(@RequestParam(name = "stuids", required = true) String stuids,
                                         @RequestParam(name = "xkdjids", required = true) String xkdjids,
                                         @RequestParam(name = "sxjxId", required = true) String sxjxId) {
        if (veJwSxjxstuService.setNoSxjxForStu(xkdjids.split(","), stuids.split(","), sxjxId)) {
            return Result.OK("设置成功!");
        }
        return Result.error("设置失败!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "选课课分班-退班")
    @ApiOperation(value = "批量退班", notes = "选课课分班-退班")
    @PostMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        if (this.veJwSxjxstuService.removeByIds(Arrays.asList(ids.split(",")))) {
            return Result.OK("退班成功!");
        }
        return Result.error("退班失败!");
    }


}
